/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package type;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author wei
 */
public enum SalesOrderType {
    normal(1),
    promo(2);
    
    private static final Map<Integer, SalesOrderType> numberToOrderTypeMap;
    private final int orderNum;

    static {
        numberToOrderTypeMap = new HashMap<Integer,SalesOrderType>();
        for (SalesOrderType orderType : EnumSet.allOf(SalesOrderType.class)) {
            numberToOrderTypeMap.put(orderType.getOrderNum(), orderType );
        }
    }

    private SalesOrderType(int orderNum) {
        this.orderNum = orderNum;
    }

    public int getOrderNum() {
        return orderNum;
    }

    public static  SalesOrderType  fromOrderNum(int value) {
        SalesOrderType ret = numberToOrderTypeMap.get(value);
        if (ret == null) {
            throw new IllegalArgumentException(); // Or just return null
        }
        return ret;
    }
}
